home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0003_INT09 Keyboard handler #1.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  99 lines

  1. {
  2. >  Does anybody know of a way to reWrite the keyboard routines, to be abl
  3. >  to read several keys at once? ReadKey will only read the last keypress
  4. >  anything else I've tried can only read the last key you have pressed d
  5. >
  6. >  For example, in many games it will let you move Forward (With the Forw
  7. >  arrow key) and shoot at the same time, With the space bar...Any sugges
  8. }
  9.  
  10. Unit POLL ;         { polled keyboard handler }
  11.                     { does not support F11 or F12 keys } Interface
  12.  
  13. Const
  14.    EscKey = 1 ;    { key codes }
  15.    aKey = 30 ;     { see TP 6 Programmers guide p 354 }
  16.    sKey = 31 ;
  17.    endKey = 79 ;
  18.    DownKey = 80 ;
  19.  
  20. Var
  21.    KeyTable : Array[ 1..127 ] of Boolean ; { KeyTable[ x ] is True when key x
  22. is pressed } { and stays True Until key x is released }
  23.  
  24. Implementation
  25.  
  26. Uses Dos, KeyIntr ;  { keyboard interrupt support }
  27.  
  28. Var
  29.    OldInt09 : Pointer ;
  30.    ExitSave : Pointer ;
  31.  
  32. {$F+} Procedure RestoreInt09 ;
  33. begin
  34.    ExitProc := ExitSave ;
  35.    SetIntVec( $09, OldInt09 ) ;
  36. end ;
  37.  
  38. {$F+} Procedure NewInt09 ; interrupt ;
  39. Var
  40.    ScanCode : Byte ;
  41.    KeyCode : Byte ;
  42. begin
  43.    STI ;
  44.    ScanCode := ReadScanCode ;
  45.    KeyCode := ScanCode and $7F ;        { strip make/break bit }
  46.    KeyTable[ KeyCode ] := ( ScanCode and $80 ) = 0 ; (* { For non C Programmers
  47. }
  48.    if ( ScanCode and $80 ) = 0  then    { make code -- key pressed }
  49.       KeyTable[ KeyCode ] := True
  50.    else                                 { break code -- key released }
  51.       KeyTable[ KeyCode ] := False ;
  52. *)
  53.    ResetKeyboard ;
  54.    EOI ;
  55. end ;
  56.  
  57. Var
  58.    N : Byte ;
  59.  
  60. begin
  61.    ExitSave := ExitProc ;
  62.    ExitProc := addr( RestoreInt09 ) ;
  63.  
  64.    For N := 1 to 127 do            { no key pressed }
  65.       KeyTable[ N ] := False ;
  66.  
  67.    GetIntVec( $09, OldInt09 ) ;
  68.    SetIntVec( $09, addr( NewInt09 ) ) ;
  69. end.
  70. {---------------------------------------------} Program TwoKeys;
  71.  
  72. Uses Crt, Poll ;  { polled keyboard handler } { ----- this Program will
  73. probably hang a debugger ----- } Var
  74.    X, Y : Byte ;
  75. begin
  76.    ClrScr ;
  77.    X := 40 ;
  78.    Y := 12 ;
  79.  
  80.    WriteLn( 'Hit keys A S  and  1 2 on the keypad' ) ;
  81.    WriteLn( ' -- Esc to stop' ) ;
  82.  
  83.    While not KeyTable[ EscKey ] do
  84.    begin
  85.       GotoXY( X, Y ) ;
  86.       Write( ' ' ) ;
  87.  
  88. { poll the KeyTable }
  89.       if KeyTable[ endKey ] and ( X > 1 ) then  Dec( X ) ;
  90.       if KeyTable[ DownKey ] and ( X < 80 ) then  Inc( X ) ;
  91.       if KeyTable[ aKey ] and ( Y > 4 ) then  Dec( Y ) ;
  92.       if KeyTable[ sKey ] and ( Y < 24 ) then  Inc( Y ) ;
  93.  
  94.       GotoXY( X, Y ) ;
  95.       Write( chr( 1 ) ) ;
  96.       Delay( 10 ) ;
  97.    end ;
  98. end.
  99.